import Vue from 'vue'
import App from './App.vue'
import { router } from './router/index';
import { appRouter, dataRouter, routers } from './router/router';
import store from "./store" //vuex
import iView from 'iview';
import 'iview/dist/styles/iview.css';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import global from "@/utils/global" //全局方法
import './assets/date-format.js'
import Highcharts from 'highcharts/highstock';
import HighchartsMore from 'highcharts/highcharts-more';
import HighchartsDrilldown from 'highcharts/modules/drilldown';
import Highcharts3D from 'highcharts/highcharts-3d';
import Highmaps from 'highcharts/modules/map';
import Constants from "@/utils/constants"
import Router from 'vue-router'
import Vant from 'vant';

import 'vant/lib/index.css';
import 'bpmn-js/dist/assets/diagram-js.css';
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css';
import 'bpmn-js/dist/assets/diagram-js.css';
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn.css';
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-codes.css';
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css';
import ErpImage from "@/components/Common/ErpImage.vue"
import ImagePreview from "@/components/Common/CImagePreview.vue"
import CTpUpload from "@/components/Common/CTpUpload.vue"
Vue.use(Vant)
Vue.use(Router)
HighchartsMore(Highcharts)
HighchartsDrilldown(Highcharts);
Highcharts3D(Highcharts);
Highmaps(Highcharts);
Vue.component("ErpImage",ErpImage);
Vue.component("TpUpload",CTpUpload);
Vue.component("ImagePreview", ImagePreview);//全局自定义组件
Vue.use(ElementUI);
Vue.use(iView);
Vue.use(global);
Vue.config.productionTip = false;
Vue.filter('taskLevelsText', function(lt) {

    return Constants.taskLevels[lt]
})
Vue.filter('long2date', function(lt) {
    if (!lt)
        return '';
    if (lt == '' || lt == null || lt < 0) return;
    var date = new Date(lt * 1000);
    return date.dateFormat('Y-m-d');
})
Vue.filter('long2datetime', function(lt) {
    if (!lt) return '';
    var date = new Date(lt * 1000);
    return date.dateFormat('Y-m-d H:i:s');
})
Vue.filter('long2datetimeweek', function(lt) {
    if (!lt) return '';
    var date = new Date(lt * 1000);
    return date.dateFormat('Y-m-d H:i:s D');
})


Vue.filter('long2datehour', function(lt) {
    if (!lt) return '';
    var date = new Date(lt * 1000);
    return date.dateFormat('Y-m-d H时');
})
Vue.filter('deadLine', function(lt) {

    if (!lt) return '';
    if (lt == '' || lt == null || lt < 0) return "";

    var lt = lt - Date.now() / 1000;
    var tips = "";

    if (lt <= 0) {
        tips = "已超期了"
        lt = 0 - lt; //
    }
    var days = Math.floor(lt / 3600 / 24);
    if (days > 0) tips += days + "天";
    lt = lt % (3600 * 24);

    var hours = Math.floor(lt / 3600);
    if (hours > 0) tips += hours + "小时";
    else {
        if (days <= 0)
            tips += ",不足1小时";
    }

    return tips;
})

Vue.filter('doHowTime', function(lt2,ltend,finish) {

    if (lt2 == '' || lt2 == null || lt2 < 0) return "";

    if (!ltend || !finish) 
    {
        ltend=Date.now() / 1000;
    }

    let lt=ltend-lt2;
    var tips = "";

    var days = Math.floor(lt / 3600 / 24);
    if (days > 0) tips += days + "天";
    lt = lt % (3600 * 24);

    var hours = Math.floor(lt / 3600);
    if (hours > 0) tips += hours + "小时";

    return tips;
})

Vue.filter('toFixed', function(lt, nb) {

    if (!lt) return '0.00';

    return lt.toFixed(nb);
})
Vue.filter('genUrl', function(country, productid) {
    return Constants.countryUrls["country"] + "/product/" + productid;
})
Vue.filter('genShopUrl', function(country, shopId) {
    return Constants.countryUrls["country"] + "/" + shopId;
})
new Vue({
    store,
    router,
    data: {
        currentPageName: ''
    },
    mounted() {

        this.$store.commit('setOpenedList');
        this.$store.commit('initCachepage');
        // 权限菜单过滤相关
        this.$store.commit('updateMenulist');
    },
    created() {
        let tagsList = [];
        let rt = [...appRouter, ...dataRouter];
        rt.map((item) => {
            if(item.children){
            if (item.children.length <= 1) {
                tagsList.push(item.children[0]);
            } else {
                tagsList.push(...item.children);
            }
        }
        });
        // debugger;
        this.$store.commit('setTagsList', tagsList);
    },
    render: h => h(App),
}).$mount('#app')